<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module optimize</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>optimize</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jgenson/Development/betelgeuse-ml/lib/ml/optimize.py">/home/jgenson/Development/betelgeuse-ml/lib/ml/optimize.py</a></font></td></tr></table>
    <p><tt>Common&nbsp;functionality&nbsp;shared&nbsp;by&nbsp;search&nbsp;heuristic-type&nbsp;optimizers.<br>
For&nbsp;example,&nbsp;you&nbsp;can&nbsp;use&nbsp;optimize&nbsp;to&nbsp;combine&nbsp;several&nbsp;optimizers&nbsp;to&nbsp;form<br>
a&nbsp;hybrid&nbsp;optimizer,&nbsp;run&nbsp;an&nbsp;optimizer&nbsp;until&nbsp;some&nbsp;condition&nbsp;has&nbsp;been&nbsp;met,&nbsp;and<br>
much&nbsp;more.<br>
&nbsp;<br>
Copyright&nbsp;(C)&nbsp;2013&nbsp;Jerrad&nbsp;Michael&nbsp;Genson<br>
&nbsp;<br>
This&nbsp;program&nbsp;is&nbsp;free&nbsp;software:&nbsp;you&nbsp;can&nbsp;redistribute&nbsp;it&nbsp;and/or&nbsp;modify<br>
it&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;the&nbsp;BSD&nbsp;3-Clause&nbsp;License&nbsp;as&nbsp;published&nbsp;by<br>
the&nbsp;Open&nbsp;Source&nbsp;Initiative.<br>
&nbsp;<br>
This&nbsp;program&nbsp;is&nbsp;distributed&nbsp;in&nbsp;the&nbsp;hope&nbsp;that&nbsp;it&nbsp;will&nbsp;be&nbsp;useful,<br>
but&nbsp;WITHOUT&nbsp;ANY&nbsp;WARRANTY;&nbsp;without&nbsp;even&nbsp;the&nbsp;implied&nbsp;warranty&nbsp;of<br>
MERCHANTABILITY&nbsp;or&nbsp;FITNESS&nbsp;FOR&nbsp;A&nbsp;PARTICULAR&nbsp;PURPOSE.&nbsp;&nbsp;See&nbsp;the<br>
BSD&nbsp;3-Clause&nbsp;License&nbsp;for&nbsp;more&nbsp;details.<br>
&nbsp;<br>
You&nbsp;should&nbsp;have&nbsp;received&nbsp;a&nbsp;copy&nbsp;of&nbsp;the&nbsp;BSD&nbsp;3-Clause&nbsp;License<br>
along&nbsp;with&nbsp;this&nbsp;program.&nbsp;&nbsp;If&nbsp;not,&nbsp;see<br>
&lt;https://betelgeuse-ml.googlecode.com/hg/LICENSE&gt;</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
    
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt><a name="-array_hash"><strong>array_hash</strong></a>(array)</dt><dd><tt>Create&nbsp;a&nbsp;single,&nbsp;numeric&nbsp;hash&nbsp;representing&nbsp;an&nbsp;array.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;array:&nbsp;A&nbsp;Numpy&nbsp;array.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;numeric&nbsp;hash.</tt></dd></dl>
 <dl><dt><a name="-array_in_arrays"><strong>array_in_arrays</strong></a>(array, arrays)</dt><dd><tt>Check&nbsp;if&nbsp;a&nbsp;Numpy&nbsp;array&nbsp;is&nbsp;contained&nbsp;in&nbsp;an&nbsp;iterable.<br>
Comparison&nbsp;is&nbsp;done&nbsp;by&nbsp;reference.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;array:&nbsp;A&nbsp;Numpy&nbsp;array&nbsp;to&nbsp;search&nbsp;array_list&nbsp;for.<br>
&nbsp;&nbsp;&nbsp;&nbsp;arrays:&nbsp;An&nbsp;iterable&nbsp;of&nbsp;Numpy&nbsp;arrays.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;True&nbsp;if&nbsp;the&nbsp;array&nbsp;is&nbsp;in&nbsp;the&nbsp;iterable.&nbsp;False&nbsp;if&nbsp;it&nbsp;is&nbsp;not.</tt></dd></dl>
 <dl><dt><a name="-array_value_equal"><strong>array_value_equal</strong></a>(array1, array2)</dt><dd><tt>Compare&nbsp;two&nbsp;Numpy&nbsp;arrays&nbsp;for&nbsp;value&nbsp;equality.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;array1:&nbsp;The&nbsp;first&nbsp;Numpy&nbsp;array&nbsp;to&nbsp;compare.<br>
&nbsp;&nbsp;&nbsp;&nbsp;array2:&nbsp;The&nbsp;second&nbsp;Numpy&nbsp;array&nbsp;to&nbsp;compare.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;True&nbsp;if&nbsp;all&nbsp;elements&nbsp;of&nbsp;array1&nbsp;and&nbsp;array2&nbsp;are&nbsp;equal.<br>
&nbsp;&nbsp;&nbsp;&nbsp;False&nbsp;if&nbsp;they&nbsp;are&nbsp;not.</tt></dd></dl>
 <dl><dt><a name="-combine_optimizers"><strong>combine_optimizers</strong></a>(optimizers, ratio)</dt><dd><tt>Combine&nbsp;an&nbsp;iterable&nbsp;of&nbsp;optimizers&nbsp;into&nbsp;one&nbsp;hybrid&nbsp;optimizer.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;optimizers:&nbsp;An&nbsp;iterable&nbsp;of&nbsp;optimizer&nbsp;functions.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Optimizer&nbsp;functions&nbsp;take&nbsp;one&nbsp;argument&nbsp;-&nbsp;a&nbsp;possible<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;solutions&nbsp;object&nbsp;-&nbsp;and&nbsp;returns&nbsp;a&nbsp;possible&nbsp;solutions&nbsp;object.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Possible&nbsp;solutions"&nbsp;can&nbsp;be&nbsp;represented&nbsp;by&nbsp;almost&nbsp;anything<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;as&nbsp;long&nbsp;as&nbsp;all&nbsp;optimizers&nbsp;share&nbsp;the&nbsp;same&nbsp;representation.<br>
&nbsp;&nbsp;&nbsp;&nbsp;ratio:&nbsp;A&nbsp;list&nbsp;of&nbsp;integers&nbsp;specifying&nbsp;the&nbsp;ratio&nbsp;to&nbsp;call&nbsp;the&nbsp;optimizer<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;functions.&nbsp;For&nbsp;a&nbsp;list&nbsp;of&nbsp;[2,&nbsp;1],&nbsp;the&nbsp;first&nbsp;optimizer&nbsp;would&nbsp;be<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;called&nbsp;twice,&nbsp;then&nbsp;the&nbsp;second&nbsp;optimizer&nbsp;would&nbsp;be&nbsp;called&nbsp;once.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;hybrid&nbsp;optimizer&nbsp;function&nbsp;that&nbsp;takes&nbsp;a&nbsp;list&nbsp;of&nbsp;possible&nbsp;solutions&nbsp;as<br>
&nbsp;&nbsp;&nbsp;&nbsp;input&nbsp;and&nbsp;returns&nbsp;a&nbsp;list&nbsp;of&nbsp;possible&nbsp;solutions&nbsp;as&nbsp;output.</tt></dd></dl>
 <dl><dt><a name="-conditional_optimize"><strong>conditional_optimize</strong></a>(possible_solutions, optimize, max_iterations<font color="#909090">=None</font>, min_quality<font color="#909090">=None</font>, check_quality<font color="#909090">=None</font>)</dt><dd><tt>Run&nbsp;an&nbsp;optimizer&nbsp;until&nbsp;certain&nbsp;conditions&nbsp;have&nbsp;been&nbsp;met&nbsp;-&nbsp;until&nbsp;the&nbsp;specified<br>
solution&nbsp;quality&nbsp;has&nbsp;been&nbsp;reached,&nbsp;or&nbsp;the&nbsp;maximum&nbsp;iterations&nbsp;have&nbsp;been<br>
exceeded,&nbsp;or&nbsp;a&nbsp;combination&nbsp;of&nbsp;both.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;possible_solutions:&nbsp;An&nbsp;initial&nbsp;iterable&nbsp;of&nbsp;of&nbsp;possible&nbsp;solutions&nbsp;to&nbsp;optimize.<br>
&nbsp;&nbsp;&nbsp;&nbsp;optimize:&nbsp;An&nbsp;optimizer&nbsp;function&nbsp;that&nbsp;takes&nbsp;possible_solutions&nbsp;as&nbsp;input,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;runs&nbsp;one&nbsp;iteration&nbsp;of&nbsp;its&nbsp;optimization&nbsp;algorithm&nbsp;on&nbsp;them,&nbsp;and<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;returns&nbsp;partially&nbsp;optimized&nbsp;possible_solutions&nbsp;as&nbsp;output.<br>
&nbsp;<br>
Keywords:<br>
&nbsp;&nbsp;&nbsp;&nbsp;max_iterations:&nbsp;The&nbsp;maximum&nbsp;number&nbsp;of&nbsp;iterations&nbsp;to&nbsp;run&nbsp;optimizer.<br>
&nbsp;&nbsp;&nbsp;&nbsp;min_quality:&nbsp;Stop&nbsp;running&nbsp;optimize&nbsp;when&nbsp;this&nbsp;solution&nbsp;quality&nbsp;has&nbsp;been<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;achieved.&nbsp;If&nbsp;this&nbsp;argument&nbsp;is&nbsp;given,&nbsp;a&nbsp;check_quality<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;argument&nbsp;must&nbsp;also&nbsp;be&nbsp;given.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;fully-optimized&nbsp;possible_solutions,&nbsp;within&nbsp;the&nbsp;constraints&nbsp;of&nbsp;the<br>
&nbsp;&nbsp;&nbsp;&nbsp;conditions&nbsp;given.</tt></dd></dl>
 <dl><dt><a name="-create_solutions"><strong>create_solutions</strong></a>(initial_solution, quantity, mutate)</dt><dd><tt>Create&nbsp;multiple&nbsp;random&nbsp;solutions&nbsp;from&nbsp;one&nbsp;initial&nbsp;arbitrary&nbsp;solution<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;Args:.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;initial_solution:&nbsp;Any&nbsp;arbitrary&nbsp;solution&nbsp;to&nbsp;the&nbsp;problem&nbsp;of&nbsp;study.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;quantity&nbsp;The&nbsp;number&nbsp;of&nbsp;solutions&nbsp;to&nbsp;create.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mutate&nbsp;A&nbsp;mutation&nbsp;function&nbsp;that&nbsp;is&nbsp;compatible&nbsp;with&nbsp;initial_solution.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Should&nbsp;take&nbsp;two&nbsp;arguments&nbsp;-&nbsp;an&nbsp;object&nbsp;of&nbsp;the&nbsp;same&nbsp;type&nbsp;as<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;initial_solution,&nbsp;and&nbsp;a&nbsp;magnitude&nbsp;between&nbsp;0&nbsp;and&nbsp;1&nbsp;for&nbsp;the<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;amount&nbsp;of&nbsp;mutation&nbsp;to&nbsp;apply.&nbsp;Should&nbsp;return&nbsp;an&nbsp;object&nbsp;also<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;of&nbsp;the&nbsp;initial_solution&nbsp;type.<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;list&nbsp;of&nbsp;randomly-generated&nbsp;problem&nbsp;solutions..</tt></dd></dl>
 <dl><dt><a name="-find_best"><strong>find_best</strong></a>(possible_solutions, check_quality)</dt><dd><tt>Find&nbsp;the&nbsp;best&nbsp;possible&nbsp;solution&nbsp;of&nbsp;the&nbsp;ones&nbsp;given.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;possible_solutions:&nbsp;An&nbsp;iterable&nbsp;of&nbsp;possible&nbsp;solutions.<br>
&nbsp;&nbsp;&nbsp;&nbsp;check_quality:&nbsp;A&nbsp;function&nbsp;that&nbsp;takes&nbsp;a&nbsp;possible&nbsp;solution&nbsp;as&nbsp;input&nbsp;and<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;returns&nbsp;the&nbsp;quality&nbsp;of&nbsp;the&nbsp;state&nbsp;as&nbsp;a&nbsp;real&nbsp;value<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;between&nbsp;0&nbsp;and&nbsp;1.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;tuple&nbsp;of&nbsp;(best_solution,&nbsp;solution_quality).</tt></dd></dl>
 <dl><dt><a name="-remove_array"><strong>remove_array</strong></a>(array, arrays)</dt><dd><tt>Remove&nbsp;a&nbsp;Numpy&nbsp;array&nbsp;from&nbsp;a&nbsp;list&nbsp;of&nbsp;arrays.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;array:&nbsp;The&nbsp;Numpy&nbsp;array&nbsp;to&nbsp;remove.<br>
&nbsp;&nbsp;&nbsp;&nbsp;arrays:&nbsp;The&nbsp;list&nbsp;of&nbsp;arrays&nbsp;to&nbsp;remove&nbsp;array&nbsp;from.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;new&nbsp;list&nbsp;of&nbsp;arrays&nbsp;sans&nbsp;the&nbsp;target&nbsp;array.</tt></dd></dl>
 <dl><dt><a name="-swap"><strong>swap</strong></a>(index1, index2, array)</dt><dd><tt>Non-destructively&nbsp;swap&nbsp;two&nbsp;elements&nbsp;in&nbsp;an&nbsp;array-like&nbsp;object.<br>
&nbsp;<br>
Args:<br>
&nbsp;&nbsp;&nbsp;&nbsp;index1:&nbsp;The&nbsp;index&nbsp;of&nbsp;the&nbsp;first&nbsp;element.<br>
&nbsp;&nbsp;&nbsp;&nbsp;index2:&nbsp;The&nbsp;index&nbsp;of&nbsp;the&nbsp;second&nbsp;element.<br>
&nbsp;&nbsp;&nbsp;&nbsp;array:&nbsp;A&nbsp;Numpy&nbsp;array-like&nbsp;object.<br>
&nbsp;<br>
Returns:<br>
&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;copy&nbsp;of&nbsp;array&nbsp;with&nbsp;swapped&nbsp;elements.</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
    
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>__contact__</strong> = 'jerradgenson@gmail.com'<br>
<strong>__copyright__</strong> = 'Copyright 2013 Jerrad Michael Genson'<br>
<strong>__license__</strong> = 'BSD 3-Clause'</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#7799ee">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
    
<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%">Jerrad&nbsp;Genson</td></tr></table>
</body></html>